<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>async</title>
</head>
<body>
<script>
    //串行
    {   //先执行完p1才会去执行p2

        let getP1 = ()=>{//3
            return Promise.resolve("p1")
        };
        let getP2 = ()=>{//2
            return Promise.resolve("p2")
        };

        let fn = async ()=>{//a->b->c
            let p1Value = await getP1();//3
            let p2Value = await getP2();//2
            console.log(p1Value,p2Value);//5
        };
        fn();
    }

    //并行
    {
        let getP1 = ()=>{//3
            return Promise.resolve("p1")
        };
        let getP2 = ()=>{//2
            return Promise.resolve("p2")
        };

        let fn = async ()=>{
            let p1 = getP1();//3
            let p2 = getP2();//2
            let p1Value = await p1;//3
            let p2Value = await p2;//2
            console.log(p1Value,p2Value);//3
        };
        fn();
    }
    //并行
    {
        let getP1 = ()=>{//3
            return Promise.resolve("p1")
        };
        let getP2 = ()=>{//2
            return Promise.resolve("p2")
        };

        let fn = async ()=>{
            let pValues = await Promise.all([getP1(),getP2()]);//3
            console.log(pValues);//3
        };
        fn();
    }




</script>
</body>
</html>